package com.bknow.aspect;

import java.util.regex.Pattern;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;

import com.bknow.model.ResultBean;
import com.bknow.model.UserInfo;

//用户参数验证
@Component
@Aspect
public class UserParamAspect {
	@Pointcut("@annotation(com.bknow.annotation.ParamValid)")
	public void ValidPoint() {
	} 
	@Around("UserParamAspect.ValidPoint() && args(..,bindingResult)")
	public Object around(ProceedingJoinPoint pjp, BindingResult bindingResult) {
		 Object retVal=null;
         try {
			if (bindingResult.hasErrors()) {
			     retVal = new ResultBean<Boolean>(402,bindingResult.getFieldError().getDefaultMessage(),false);
			 } else {
			     retVal = pjp.proceed();
			 }
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
         return retVal;
	}
}
